<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>视图层</title>
</head>

<body>
  <div id="app"></div>
  <!-- vue渲染 -->
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script src="./bridge.js"></script>
  <!-- 开发者写法 -->
  <script type="wxml">
    <wx-text>这是详情页</wx-text>
  </script>
  <script>
    let vm = null;
    window._bridge.onMessage((res) => {
      // new Vue({
      //   el: '#app',
      //   data() {
      //     return res.data;
      //   },
      //   components: {
      //     'wx-text': {
      //       template: '<span><slot></slot></span>'
      //     }
      //   },
      // template: `<wx-text>这是详情页{{name}}</wx-text>`
      // })
      console.log(res.type,'type--')
      if (res.type === 'initSet') {
        vm = new Vue({
          el: '#app',
          data() {
            return res.data;
          },
          components: {
            'wx-text': {
              template: '<span><slot></slot></span>'
            }
          },
          template: document.querySelector("[type = 'wxml']").innerHTML
        })
      }
      else if(res.type === 'setData') {
        for(let key in res.data) {
          vm[key] = res.data[key]
        }
      }

    });
  </script>
</body>

</html>